CREATE PROCEDURE reszleg_torol @reszlegid int as
declare @kod int
/*egy parametkent tartozo reszleget torol ki es minden adatot ami ahhoz
a reszleghez tartozik */
begin transaction
set transaction isolation level serializable

declare c cursor for
select r.id
from reszleg l,cella c,rab r
where l.id=c.reszleg_id and c.id=r.cella_id and l.id=@reszlegid

open c
fetch next from c into @kod
while @@fetch_status=0 
begin
delete from rabbunteny where rab_id=@kod
if @@error<>0 rollback transaction
delete from rabirat where rab_id=@kod
if @@error<>0 rollback transaction
delete from rabujjlenyomat where rab_id=@kod
if @@error<>0 rollback transaction
delete from rab where id=@kod
if @@error<>0 rollback transaction
fetch next from c into @kod
end
close c
deallocate c


delete from cella where reszleg_id=@reszlegid
if @@error<>0 rollback transaction
delete from orreszleg where reszleg_id=@reszlegid
if @@error<>0 rollback transaction
delete from reszleg where id=@reszlegid
if @@error<>0 rollback transaction

commit transaction
